package com.linkturing.util;

import java.util.List;
import java.util.Set;

import com.alibaba.fastjson.JSON;
import com.linkturing.serial.HttpClientUtil;
import com.linkturing.swing.LtProductQualityBasic;

public class BizHelper {

	static String base_url = "http://124.70.61.16:8888/jeecg-boot";
	//static String base_url = "http://192.168.2.139:8080/jeecg-boot";
	//static String base_url = "http://192.168.2.44:8888/jeecg-boot";
	//static String base_url = "http://192.168.2.160:8080/jeecg-boot";
	static String login_url = "/sys/loginNC";
	
	static String addbatch_url = "/erp/ltWeighing/addBactch"; 
	
	public static String postBatch(String json,String token) {
		return post(addbatch_url,json,token);
	}
	
	public static LoginResult doLogin(User user) {
		String result = post(login_url,JSON.toJSONString(user),"");
		System.out.println(result);
		LoginResult lr = JSON.toJavaObject(JSON.parseObject(result), LoginResult.class);
		if(lr!=null) {
			if(lr.isSuccess()) {
				JedisUtil.set(Constants.login_user, user.getUsername(), 60*60);
				JedisUtil.set(Constants.user+user.getUsername(), lr.getResult().getToken(), 60*60);
				//XinhuaApplication.lblNewLabel_1_1.setText(user.getUsername());
			}
		}
		return lr;
	}
	
	public static String post(String url,String json,String token) {
    	url = base_url + url;
    	
    	return HttpClientUtil.sendPost(url, json,token);
    }
	
	
	public static boolean isExitFenjuanhao(String key,String juanhao,String fjh) {
		List<String> jsonList = JedisUtil.getList(key);
		if(jsonList!=null) {
        	for(int i=0;i<jsonList.size();i++) {
        		String json = jsonList.get(i);
        		LtProductQualityBasic bean = JSON.toJavaObject(JSON.parseObject(json), LtProductQualityBasic.class);
        		if(fjh.equals(bean.getVolumeNumber())&&juanhao.equals(bean.getReelNumber())) {
        			return true;
        		}
        	}
        }
		
		return false;
	}
	
	public static void main(String[] args) {

		 Set<String> keys = JedisUtil.keys("2021-05-17:weight:*");
		 System.out.println(keys);
		List<String> list = JedisUtil.getList("2021-05-17:weight:*");
		System.out.println(list);
		
	}

}
